package com.example.chapp.control;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.example.chapp.R;
import com.example.chapp.entity.*;
import com.example.chapp.listutil.*;
import com.example.chapp.util.HttpCallback;
import com.example.chapp.util.httputil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class study2activity extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.study2);
        request();
        //**************
        View but1=findViewById(R.id.sy);
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(study2activity.this, shouyeactive.class);
                startActivity(intent);
            }
        });
        View but2=findViewById(R.id.wd);
        but2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(study2activity.this, wodeactive.class);
                startActivity(intent);
            }
        });
        View jj=findViewById(R.id.jj);
        jj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(study2activity.this, study1activity.class);
                startActivity(intent);
            }
        });
    }
    public void request(){
        httputil.sendRequest("http://192.168.223.1:8080/getd/1", "GET", null, new HttpCallback() {
            @Override
            public void onSuccess(InputStream in) {
                Gson gson=new Gson();
                result  r=gson.fromJson(httputil.decodeAsString(in),new TypeToken<result<List<discourage>>>(){}.getType());
                List<discourage> l= (List<discourage>) r.getData();
                s2list shouyelist=new s2list(l,study2activity.this);
                ListView listView=findViewById(R.id.s2list);
                listView.setAdapter(shouyelist);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent=new Intent(study2activity.this, study1activity.class);
                        startActivity(intent);
                    }
                });

            }

            @Override
            public void onFailure(int code, String mes) {

            }
        });
    }
}
